<h3>Recent &amp; Archives</h3>

<ul class="nav nav-tabs" id="side-bar-tabs">
    <li  class="active"><a href="#recent" data-toggle="tab">Recent</a></li>
    <!--    <li ><a href="#popular" data-toggle="tab">Popular</a></li>-->   
    <li><a href="#archives" data-toggle="tab">Archives</a></li>
</ul>
<div class="tab-content">
    <!--    <div class="tab-pane active" id="popular">
            <ul class="list-popular-content  clearfix">
                <li>
                    <img src="<?php echo Yii::app()->theme->baseUrl; ?>/img/blog/small1.jpg" width="65" height="65" alt="Small blog image" class="pull-left" />
                    <h5><a href="#" title="Example blog article">How to buy this theme</a></h5>
                    <div>this is a summary of the content...</div>
                </li>
                <li>
                    <img src="<?php echo Yii::app()->theme->baseUrl; ?>/img/blog/small2.jpg" width="65" height="65" alt="Small blog image" class="pull-left"/>
                    <h5><a href="#" title="Example blog article">Guide to CSS3</a></h5>
                    <div>this is a summary of the content...</div>
                </li>
                <li>
                    <img src="<?php echo Yii::app()->theme->baseUrl; ?>/img/blog/small3.jpg" width="65" height="65" alt="Small blog image" class="pull-left"/>
                    <h5><a href="#" title="Example blog article">Moved to a new building</a></h5>
                    <div>this is a summary of the content...</div>
                </li>
                <li>
                    <img src="<?php echo Yii::app()->theme->baseUrl; ?>/img/blog/small4.jpg" width="65" height="65" alt="Small blog image" class="pull-left"/>
                    <h5><a href="#" title="Example blog article">Choose the right theme</a></h5>
                    <div>this is a summary of the content...</div>
                </li>
                <li>
                    <img src="<?php echo Yii::app()->theme->baseUrl; ?>/img/blog/small5.jpg" width="65" height="65" alt="Small blog image" class="pull-left" />
                    <h5><a href="#" title="Example blog article">Why use bootstrap</a></h5>
                    <div>this is a summary of the content...</div>
                </li>
            </ul>
        </div>-->
    <div class="tab-pane active" id="recent">
        <ul class="list-recent-content ">
            <?php foreach ($recentBlog as $recentBlogval) { ?>
                <li>               
                    <h5><?php echo CHtml::link($recentBlogval->title, $recentBlogval->url) ?></h5>

                </li><?php } ?>        </ul>
    </div>
    <div class="tab-pane" id="archives">
        <ul class="list-recent-content">
            <?php
            $monthsvalue = array('01' => 'January', '02' => 'Feburary', '03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December');
            $condition = new CDbCriteria;
            $condition->select = 'YEAR(t.create_time) as year'; //declare year in post model model
            $condition->distinct = true;
            $condition->order = 'create_time DESC';
            $yeardataarticle = Post::model()->findAll($condition);
            foreach ($yeardataarticle as $ya):
                $year = $ya->year;
                echo '<div class="arcivesYear">' . $year . '</div>';
                $monthcriteria = new CDbCriteria;
                $monthcriteria->select = 'MONTH(t.create_time) as month'; // declare month in post model
                $monthcriteria->condition = 'YEAR(t.create_time)=:year';
                $monthcriteria->params = array(':year' => $year);
                $monthcriteria->order = 'create_time DESC';
                $months = Post::model()->findAll($monthcriteria);
                foreach ($months as $month):
                    $montth = $month->month;
                    $urlMonth = ($montth > 9) ? $montth : '0' . $montth;
                    foreach ($monthsvalue as $key => $value):
                        if (!isset(${'printed' . $key . $year}))
                            ${'printed' . $key . $year} = false;

                        //var_dump('printed'.$key.$year);exit; 
                        if ($key == $montth and !${'printed' . $key . $year}) {
                            ?>
                            <div><?php
                echo CHtml::link($value, array('/' . $year . '-' . $urlMonth));
                ${'printed' . $key . $year} = true;
                            ?><?php
                $postcount = new CDbCriteria;
                $postcount->addCondition('MONTH(t.create_time)=:month AND YEAR(t.create_time)=:year');
                $postcount->params = array(':month' => $montth, ':year' => $year);
              $count = Post::model()->count($postcount);
                echo ' (' . $count . ')';
                            ?>    </div>
                            <?php
                        }

                    endforeach;

                endforeach;

            endforeach;
            ?>


        </ul>
    </div>
</div>

